package com.chen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chen.entity.AccountA;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;

@Mapper
public interface AccountAMapper extends BaseMapper<AccountA> {

    @Update("update account_a set dollar = dollar - #{dollarAmount} ,dollar_frozen = dollar_frozen + #{dollarAmount} where user_id = #{userId} and dollar_frozen = 0")
    int frozenDollarAmount(@Param("userId") int userId, @Param("dollarAmount") BigDecimal dollarAmount);

    @Update("update account_a set dollar_frozen =dollar_frozen -  #{dollarAmount},rmb = rmb + #{dollarAmount} * 7 where user_id = #{userId} and dollar_frozen > 0")
    void commitDollarToRmb(@Param("userId") int userId, @Param("dollarAmount") BigDecimal dollarAmount);

    @Update("update account_a set dollar_frozen = dollar_frozen - #{dollarAmount},dollar = dollar + #{dollarAmount} where user_id = #{userId} and dollar_frozen > 0")
    void cancelDollarToRmb(@Param("userId") int userId, @Param("dollarAmount") BigDecimal dollarAmount);
}
